'use strict';

const { Controller } = require('egg');

class LoginController extends Controller {
  async index() {
    const { ctx } = this;
    let params = ctx.request.body   
    //需要存储的 token 数据
    let token_con = {
        'username': params.username,
        'password': params.password,
        }
    let term = (60 * 60 * 24) + 's' //token有效期,设置为24小时
    const token = ctx.app.jwt.sign(token_con, ctx.app.config.jwt.secret, { expiresIn: term });
    ctx.body = token;
  }
}

module.exports = LoginController;
